package com.android.paipaiguoji.wxapi;


import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.Toast;

import com.android.paipaiguoji.activity.BaseObject;
import com.android.paipaiguoji.activity.DirectBuyGoodsDetailActivity;
import com.android.paipaiguoji.activity.WapPay;
import com.android.paipaiguoji.activity.mine.BuyTicketActivity;
import com.android.paipaiguoji.activity.mine.DirectBuyPayOrderActivity1;
import com.android.paipaiguoji.utils.ConstantsUrl;
import com.android.paipaiguoji.utils.MyLog;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

	private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";
	
    private IWXAPI api;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.pay_result);
//
    	api = WXAPIFactory.createWXAPI(this, ConstantsUrl.WX_APPID);
        api.handleIntent(getIntent(), this);
    }

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
        api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}

	@Override
	public void onResp(BaseResp resp) {

		int code = resp.errCode;

		if (code == 0){
			if( BaseObject.instance!=null){
					BaseObject.instance.finish();

			}
			if(  BuyTicketActivity.instance!=null){
				BuyTicketActivity.instance.finish();

			}
			if( DirectBuyPayOrderActivity1.instance!=null){
				DirectBuyPayOrderActivity1.instance.finish();

			}
			if( DirectBuyGoodsDetailActivity.instance!=null){
				DirectBuyGoodsDetailActivity.instance.finish();

			}
			//显示充值成功的页面和需要的操作

//			\\weixin

		}
		if (code == -1){
			//错误
//			Toast.makeText(getApplicationContext(),"code == -1",Toast.LENGTH_SHORT).show();
		}

		if (code == -2){

			//用户取消
//			Toast.makeText(getApplicationContext(),"code == -2",Toast.LENGTH_SHORT).show();
		}

//		Log.d(TAG, "onPayFinish, errCode = " + resp.errCode);
//		MyLog.e("inest","baseResp.getType()="+3);
//		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
//			AlertDialog.Builder builder = new AlertDialog.Builder(this);
//			builder.setTitle("asdasdasds");
//		builder.show();
//			builder.setMessage(getString(1, ""));

//			Intent intent=new Intent(this, MainActivity.class);
//
//			startActivity(intent);

//		}
		finish();
	}
}